package com.rykj.qxj.test.xtest;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.rykj.qxj.result.BaseResponse;

public class JavaBeanToJsonString {
	public static void main(String[] args) {
		
		Map<String,Object> map1=new HashMap<String,Object>();
		map1.put("name", "aa");
		map1.put("id", 10);
		
		Map<String,Object> map2=new HashMap<String,Object>();
		map2.put("name", "aa");
		map2.put("id", 10);
		
		Map<String,Object> map3=new HashMap<String,Object>();
		map3.put("name", "aa");
		map3.put("id", 10);
		
		Map<String,Object> map4=new HashMap<String,Object>();
		map4.put("name", "aa");
		map4.put("id", 10);
		
	   List<Map<String,Object>> testList=new ArrayList<Map<String,Object>>();
	   testList.add(map1);
	   testList.add(map2);
	   testList.add(map3);
	   testList.add(map4);
		
		BaseResponse baseResponse=new BaseResponse("200","调用成功",testList);
		
		Object json = JSON.toJSON(baseResponse);
		//System.out.println(baseResponse.toString());
		
		//System.out.println(json.toString());
		
		ObjectMapper mapper=new ObjectMapper();
		String writeValueAsString="";
		try {
			writeValueAsString= mapper.writeValueAsString(baseResponse);
		} catch (JsonProcessingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println(writeValueAsString);
		
	}

}
